package cn.com.w.jdk8.demo.controller;

import cn.com.w.jdk8.demo.exception.BadRequestException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/custom")
public class CustomHttpCodeController {

    Logger logger = LoggerFactory.getLogger(getClass());



    @GetMapping("/test")
    public String test(@RequestParam(name = "id") Integer id){


        if (id <10) {
            throw new BadRequestException();
        }

        return "ok1!";
    }

    @GetMapping("/test1")
    public String test1(@RequestParam(name = "id") Integer id, HttpServletResponse response){


        if (id <10) {
            // 自定义返回status
            response.setStatus(1234);
        }

        return "ok2!";
    }


}
